<%@ Assembly Name="PowerShellConsole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9dfb602056ea0b96" %>
<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="PowerShellConsole.PageCode.PSConsole" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>    
<%@ Register TagPrefix="wssuc" TagName="InputFormSection" Src="/_controltemplates/InputFormSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="InputFormControl" Src="/_controltemplates/InputFormControl.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ButtonSection" Src="/_controltemplates/ButtonSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBar" src="~/_controltemplates/ToolBar.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" src="~/_controltemplates/ToolBarButton.ascx" %>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
    runat="server">
    PowerShell Console
</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
    PowerShell Console
</asp:Content>

<asp:Content ID="PageDescription" ContentPlaceHolderID="PlaceHolderPageDescription" runat="server">
    <br />
    Administrators can use this page to run PowerShell scripts
    <br />
    &nbsp;
</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <style>
        .output
        {
            display:inline-block;

        }
        .frame 
        {
            font-family: Courier New;
            font-weight: bold;
            background-color: #012456;
            color: #eeedf0;
            overflow: auto;
            height:600px;
            width:800px;
        }
        .frame pre 
        {
            margin: 0;
        }
        .input
        {
            width: 800px;
            font-family: Courier New;
            font-weight: bold;
            font-size: 14px;
            background-color: #012456;
            color: #eeedf0;
        }
    </style>
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        <Scripts>
            <asp:ScriptReference Path="/_layouts/PSC/js/start.js" />
            <asp:ScriptReference Path="/_layouts/PSC/js/jquery-1.3.2.js" />
        </Scripts>
    </asp:ScriptManager>
    <asp:Table CellSpacing="0" CellPadding="0" BorderWidth="0" CssClass="ms-propertysheet">
        <tr>
            <td colspan="2">
			<wssuc:ToolBar id="rctScrToolbar" runat="server">
				<Template_Buttons>
					<wssuc:ToolBarButton runat="server" Text="Save"
						id="btnSave"
						ToolTip="Save the current script"
						OnClick="btnSave_OnClick" ImageUrl="/_layouts/images/newitem.gif"
						AccessKey="C" />
					<span id="Span2" runat="server">
						<asp:Label ID="lblSaved" Text="Saved scripts" AssociatedControlId="ddlSavedScripts" runat="server" />
						<asp:DropDownList id="ddlSavedScripts" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlSavedScripts_SelectedIndexChanged" Width="200" />
					</span>
					<wssuc:ToolBarButton runat="server" Text="Open script library"
					    id="btnOpenScriptLibrary"
					    ToolTip="Open script library"
					    OnClick="btnOpenScriptLibrary_OnClick" 
					    AccessKey="L" />
				</Template_Buttons>
		        <Template_RightButtons>
					<span id="Span1" runat="server">
						<asp:Label ID="lblRecent" Text="Recent scripts" AssociatedControlId="ddlRecentScripts" runat="server" />
						<asp:DropDownList id="ddlRecentScripts" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlRecentScripts_SelectedIndexChanged" Width="200" />
					</span>
		        </Template_RightButtons>
			</wssuc:ToolBar>
            </td>
        </tr>
        
        <wssuc:InputFormSection Title="Upload a script" Description="Select your script to be uploaded and run" runat="server">
            <template_inputformcontrols>
                <wssuc:InputFormControl runat="server" LabelText="">
                    <Template_Control>
	                    <asp:FileUpload ID="uplScript" runat="server" CssClass="ms-fileinput" />
	                    <asp:Button ID="btnUpload" runat="server" Text="Upload and run" OnClick="btnUpload_OnClick" AccessKey="U"
	                        CssClass="ms-input" />
                    </Template_Control>
                </wssuc:InputFormControl>
            </template_inputformcontrols>
        </wssuc:InputFormSection>

        <wssuc:InputFormSection Title="Interactive scripting" Description="Type your commands here" runat="server">
            <template_inputformcontrols>
                <wssuc:InputFormControl runat="server" LabelText="">
                    <Template_Control>
                        <pre><asp:TextBox runat="server" id="txtCommand" TextMode="Multiline" Width="800" Height="100" /></pre>
                        <asp:Button runat="server" id="btnRun" Text="Run" onClick="btnRun_OnClick" CssClass="ms-input" />
                        <asp:Label ID="lblConsole" runat="server" BackColor="Black" />
                    </Template_Control>
                </wssuc:InputFormControl>
            </template_inputformcontrols>
        </wssuc:InputFormSection>
        
        <wssuc:InputFormSection Title="Execution output" Description="" runat="server">
            <template_inputformcontrols>
                <wssuc:InputFormControl runat="server" LabelText="">
                    <Template_Control>
                        <code>
                            <asp:Literal runat="server" id="lblOutput" />
                        </code>
                    </Template_Control>
                </wssuc:InputFormControl>
            </template_inputformcontrols>
        </wssuc:InputFormSection>
        
        <wssuc:InputFormSection Title="Execution errors" Description="" runat="server">
            <template_inputformcontrols>
                <wssuc:InputFormControl runat="server" LabelText="">
                    <Template_Control>
                        <code>
                            <asp:Label runat="server" id="lblError" />
                        </code>
                    </Template_Control>
                </wssuc:InputFormControl>
            </template_inputformcontrols>
        </wssuc:InputFormSection>

        <wssuc:InputFormSection Title="Interactive console" Description="" runat="server">
            <template_inputformcontrols>
                <wssuc:InputFormControl runat="server" LabelText="">
                    <Template_Control>
                        <div class="frame" ID="divFrame">
                            <pre><span ID="lblConsoleOutput" class="output"></span><br /></pre>
                        </div>
                        <input type="text" ID="txtInput" class="input" onKeyPress="return inputPress(event)" />
                    </Template_Control>
                </wssuc:InputFormControl>
            </template_inputformcontrols>
        </wssuc:InputFormSection>

        <wssuc:ButtonSection runat="server" ShowStandardCancelButton="false">
            <template_buttons>
           <asp:PlaceHolder runat="server">
				<asp:Button UseSubmitBehavior="false" runat="server" class="ms-ButtonHeightWidth" onClick="buttonClose_OnClick" Text="Close" id="buttonClose" causesvalidation=false />
            </asp:PlaceHolder>
        </template_buttons>
        </wssuc:ButtonSection>
    </asp:Table>

    <script type="text/javascript">
        function inputPress(e) {
	    var key;
	    if (window.event) {
	        key = window.event.keyCode; // IE
	    } else {
	        key = e.which; // firefox
	    }
	    if (key == 13) {
	        var command = $('#txtInput').val();
	        if (command == "cls") {
	            $("#lblConsoleOutput").text("");
	        } else {
	            PageMethods.Execute(command, function(result, userContext, methodName) {
	                $("#lblConsoleOutput").append(result);
	                $("#divFrame").scrollTop($("#lblConsoleOutput").height());
	            });
	        }
	        document.getElementById('txtInput').value = '';
	        return false;
	    } else {
	        return true;
	    }
	}
    </script>
</asp:Content> 

